package bookstudytest;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Created by swordbone on 2017/11/17.
 */
public class TimerAction implements ActionListener {
    @Override
//   定义定时器的事件
    public void actionPerformed(ActionEvent e) {
        System.out.println("大哥你好！");
        Toolkit.getDefaultToolkit().beep();
    }
    public static void main(String[] args){
        ActionListener actionListener = new TimerAction();
//        定时器，传入时间和事件
        javax.swing.Timer timer = new javax.swing.Timer(10000,actionListener);
//        开始定时器
        timer.start();
//        显示一个提示框，同时定时器也在启动
        JOptionPane.showMessageDialog(null,"quit program?");
        System.exit(0);
    }
}
